#!/usr/bin/python
# -*- coding: utf-8 -*-
"""docstrings
"""


from contact.business import security

class RequestFilterMiddleware(object):
    """请求过滤辅助中间件
    
    负责校验用户的请求，格式化参数输入等
    
    request.DATAS
    """
    
    def process_view(self, request, view_func, view_args, view_kwargs):
        s = request.REQUEST.get('ENCODE_DATAS', None)
        if not s:
            return None
        user = request.REQUEST['user']
        key = self._get_password(user)
        datas = security.decode(s, key)
        setattr(request, 'DATAS', datas) 
        return None
    
    def _get_password(self, username):
        return username